using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using net_work.Data.Entity.Appr;
using net_work.Data.Enum.Appr;

namespace net_work.Config.DataBaseConfig.Appr;

/// <summary>
/// 审批实例历史记录实体配置类
/// </summary>
public class ApprovalInstanceHistoryEntityTypeConfiguration : IEntityTypeConfiguration<ApprovalInstanceHistory>
{
    public void Configure(EntityTypeBuilder<ApprovalInstanceHistory> builder)
    {
        builder.ToTable("appr_inst_hty");

        builder.HasKey(aih => aih.Id);

        // 配置字段名映射
        builder.Property(aih => aih.Id).HasColumnName("inst_hty_id");

        // 将 ApprovalResult 枚举存储为字符串
        builder.Property(aih => aih.Result)
            .HasColumnName("inst_hty_result")
            .IsRequired()
            .HasMaxLength(64)
            .HasConversion(
                v => v.ToString(),
                v => (ApprovalResult)Enum.Parse(typeof(ApprovalResult), v)
            );

        builder.Property(aih => aih.Content).HasColumnName("inst_hty_cnt").IsRequired().HasMaxLength(64);
        builder.Property(aih => aih.InstanceId).HasColumnName("inst_id").IsRequired();
        builder.Property(aih => aih.FlowNodeId).HasColumnName("flow_node_id").IsRequired();

        builder.Property(aih => aih.CreatedBy).HasColumnName("create_by").IsRequired().HasMaxLength(64);
        builder.Property(aih => aih.CreatedTime).HasColumnName("create_time").IsRequired();
        builder.Property(aih => aih.UpdatedBy).HasColumnName("update_by").IsRequired().HasMaxLength(64);
        builder.Property(aih => aih.UpdatedTime).HasColumnName("update_time").IsRequired();
        builder.Property(aih => aih.Remark).HasColumnName("remark").HasMaxLength(256);
        builder.Property(aih => aih.DelFlag).HasColumnName("del_flag").HasDefaultValue('0');
    }
}